package com.bnq.rnmodule.rnupdater;

/**
 * Created by guoxing on 25/10/2017.
 */
import android.Manifest;
import android.widget.Toast;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class rnupdaterModule extends ReactContextBaseJavaModule {
    public rnupdaterModule (ReactApplicationContext reactContext) {
        super(reactContext);
    }
    @Override
    public String getName() {
        return "RNAppUpdater";
    }
    @ReactMethod
    public void downApkAsync(final boolean isFouce, final String url){
//        downApkAndInstall.start(isFouce,url,getCurrentActivity());
        PermissionUtils.permissionsCheck(getCurrentActivity(),new String[]{
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE},new PermissionUtils.OnPermissionListener() {
            @Override
            public void onPermissionGranted() {
                downApkAndInstall.start(isFouce,url,getCurrentActivity());
            }

            @Override
            public void onPermissionDenied(String[] deniedPermissions) {
                Toast.makeText(getCurrentActivity(), "权限不够,无法下载安装！", Toast.LENGTH_SHORT).show();

            }});
    }
}
